<?php
/**
 * Name: AdminAuthController.class.php
 * Description:
 * User: DIY
 * Date: 2016/9/6
 * Time: 18:36
 */

namespace Admin\Controller;

use Admin\Library\BootstrapPage;
use Common\Model\AdminAuthModel;


class AdminAuthController extends BaseController{

    /*
     * 列表页面
     * */
    public function index(){
        $data = I('get.');
        $AdminAuthModel = new AdminAuthModel();
        $count = $AdminAuthModel->getAdminAuthCount($data);
        $Page = new BootstrapPage($count,20);
        $limit = $Page->firstRow.','.$Page->listRows;
        $list['list'] = $AdminAuthModel->getAdminAuthList($data,$limit);
        $list['page'] = $Page->show();// 分页显示输出
        $this->assign('list',$list);
        $this->display();
    }

    /*
     * 新增权限
     * */
    public function add(){
        if(IS_POST){
            $AdminAuthModel = new AdminAuthModel();
            if($AdminAuthModel->create()){
                $result = $AdminAuthModel->add(); // 写入数据到数据库
                if($result){
                    $this->success('保存成功',U('Admin/AdminAuth/index'));
                }
            }
            $this->error('保存失败');
        }
        else{
            $AdminAuthModel = new AdminAuthModel();
            $menu = $AdminAuthModel->getAdminAuthList();
            $this->assign('menu',$menu);
            $this->display();
        }
    }

    /*
     * 删除
     * */
    public function del($id){
        $AdminAuthModel = new AdminAuthModel();
        $AdminAuthModel->delete($id);
        $this->success('删除成功',U('Admin/AdminAuth/index'));

    }

    /*
     * 编辑
     * */
    public function edit($id){
        $AdminAuthModel = new AdminAuthModel();
        if(IS_POST){
            if($AdminAuthModel->create()){
                $result = $AdminAuthModel->save();
                if($result){
                    $this->success('更新成功',U('Admin/AdminAuth/index'));
                }
            }
            $this->error('更新失败');

        }
        else{
            $AdminAuthModel = new AdminAuthModel();
            $menu = $AdminAuthModel->getAdminAuthList();
            $auth = $AdminAuthModel->find($id);
            $this->assign('auth',$auth);
            $this->assign('menu',$menu);
            $this->display();
        }
    }
}